<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <input type="text" class="pwd" />
    <script>
      var pwdEle = document.querySelector(".pwd");
      pwdEle.onblur = function () {
        var val = this.value;
        if (val.length > 8) {
          var reg1 = /(^\d+$)|(^[a-zA-Z]+$)/;
          if (reg1.test(val)) {
            console.log("密码强度低");
          } else {
            var reg2 = /\d/; // 匹配数字
            var reg3 = /[a-zA-Z]/; // 匹配字母
            var reg4 = /[A-Z]/;
            var reg5 = /_/;
            if (
              reg2.test(val) &&
              reg3.test(val) &&
              reg4.test(val) &&
              reg5.test(val)
            ) {
              console.log("密码强度强");
            } else {
              if (reg2.test(val) && reg3.test(val)) {
                console.log("密码强度中");
              }
            }
          }
        } else {
          console.log("密码必须大于8位");
        }
      };
    </script>
  </body>
</html>
